package se.sll.itintegration.catalogue.gui.service.view.users;

import java.util.ArrayList;
import java.util.List;

import se.sll.itintegration.catalogue.gui.entity.UserEntity;
import se.sll.service.catalogue.common.Translator;
import se.sll.service.catalogue.common.rest.model.user.User;

/**
 * Translates from List<UserEntity> to List<User>.
 * 
 * @author Christer Palm, Nogui
 */
public class UserListTranslator implements Translator<List<UserEntity>, List<User>> {
    private static final UserListTranslator INSTANCE = new UserListTranslator();

    private UserListTranslator() {
    }

    @Override
    public List<User> translate(List<UserEntity> from) {
        return translateTo(from, new ArrayList<User>());
    }

    @Override
    public List<User> translateTo(List<UserEntity> from, List<User> to) {
        for (UserEntity ue : from) {
            User u = UserTranslator.getInstance().translate(ue);
            to.add(u);
        }
        return to;
    }

    public static UserListTranslator getInstance() {
        return INSTANCE;
    }
}
